using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml;
using Thinxoft.HttpLib;
using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Media;

namespace Thinxoft.XedusLive
{
	/// <summary>
	/// Summary description for WebAdmin.
	/// </summary>
	public partial class WebAdmin : System.Windows.Forms.Form
    {
        private IContainer components;
        private System.Windows.Forms.ListBox appList;
        private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.TabControl tabApps;
		private System.Windows.Forms.TabControl tabGlobal;
        private System.Windows.Forms.TabPage tabPage3;
        private System.Windows.Forms.TabPage tabPage5;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtLocation2;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox txtApp2;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.Button btnUplaod;
		private System.Windows.Forms.Button btnOpen;
		private System.Windows.Forms.OpenFileDialog openFile;
		private System.Windows.Forms.ListView listView;
		
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage6;
		private System.Windows.Forms.TabPage tabPage7;
		private System.Windows.Forms.ListView listViewFiles;
        private System.Windows.Forms.Button btnRemove;
        string[] files;
        string app;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox txtDefaultDocs2;
        private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.MenuItem menuItem7;
		private System.Windows.Forms.MenuItem menuItem8;
		private System.Windows.Forms.MenuItem menuItem9;
		private System.Windows.Forms.MenuItem menuItem10;
		private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        Settings settings;
        private Button btnSecurity;
        Dictionary<string, string> dirfiles;
        private ToolTip toolTip1;
        private Button btnGetLocation;
        private GroupBox groupBox1;
        private ImageList imageList1;
        private MenuStrip menuStrip1;
        private ToolStripMenuItem actionsToolStripMenuItem;
        private ToolStripMenuItem editToolStripMenuItem;
        private ToolStripMenuItem useNotepadToolStripMenuItem;
        private ToolStripMenuItem deleteFolderToolStripMenuItem;
        private ToolStripMenuItem openFolderToolStripMenuItem;
        private MenuItem btnShutdown;
        private TabPage tabPage4;
        private TabPage tabPage8;
        private Register registerTab;
        private ConnectToNowForm connectToNowTab;
        string currentpath;
        
        


        public WebAdmin()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            

			settings = Start.XedusState.XedusSettings;

			foreach(HttpApplication app in settings.HttpApplications )
			{
				appList.Items.Add(app.Name);
			}
            
			
			this.appList.SelectedIndex = 0;
			this.app = (string)this.appList.SelectedItem;

            //btnSecurity_Click(null, null);

            connectToNowTab.LoadData();
            SetXssState();
        }

        public void ShowRegistration()
        {
            tabGlobal.SelectedIndex = 3;
            this.Show();
        }
        public void ShowConnection()
        {
            
            tabGlobal.SelectedIndex = 2;
            this.Show();
        }


        private void SetXssState()
        {
            if (Start.XedusState.XedusSettings.BlockXSS)
            {
                btnSecurity.Text = "Allow XSS chars";
                this.btnSecurity.BackgroundImage = Properties.Resources.enable;
            }
            else
            {
                btnSecurity.Text = "Block XSS chars";
                this.btnSecurity.BackgroundImage = Properties.Resources.disable;
            }
        }

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WebAdmin));
            this.appList = new System.Windows.Forms.ListBox();
            this.tabGlobal = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.tabApps = new System.Windows.Forms.TabControl();
            this.tabPage3 = new System.Windows.Forms.TabPage();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.button3 = new System.Windows.Forms.Button();
            this.btnSecurity = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button1 = new System.Windows.Forms.Button();
            this.tabPage5 = new System.Windows.Forms.TabPage();
            this.btnGetLocation = new System.Windows.Forms.Button();
            this.label5 = new System.Windows.Forms.Label();
            this.txtLocation2 = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.txtDefaultDocs2 = new System.Windows.Forms.TextBox();
            this.txtApp2 = new System.Windows.Forms.TextBox();
            this.btnSave = new System.Windows.Forms.Button();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage6 = new System.Windows.Forms.TabPage();
            this.listViewFiles = new System.Windows.Forms.ListView();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.actionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.deleteFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.useNotepadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.tabPage7 = new System.Windows.Forms.TabPage();
            this.btnRemove = new System.Windows.Forms.Button();
            this.btnOpen = new System.Windows.Forms.Button();
            this.listView = new System.Windows.Forms.ListView();
            this.btnUplaod = new System.Windows.Forms.Button();
            this.tabPage4 = new System.Windows.Forms.TabPage();
            this.connectToNowTab = new Thinxoft.XedusLive.ConnectToNowForm();
            this.tabPage8 = new System.Windows.Forms.TabPage();
            this.registerTab = new Thinxoft.XedusLive.Register();
            this.openFile = new System.Windows.Forms.OpenFileDialog();
            this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.menuItem5 = new System.Windows.Forms.MenuItem();
            this.menuItem6 = new System.Windows.Forms.MenuItem();
            this.menuItem7 = new System.Windows.Forms.MenuItem();
            this.menuItem9 = new System.Windows.Forms.MenuItem();
            this.menuItem10 = new System.Windows.Forms.MenuItem();
            this.menuItem8 = new System.Windows.Forms.MenuItem();
            this.btnShutdown = new System.Windows.Forms.MenuItem();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.tabGlobal.SuspendLayout();
            this.tabPage1.SuspendLayout();
            this.tabApps.SuspendLayout();
            this.tabPage3.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.tabPage5.SuspendLayout();
            this.tabPage2.SuspendLayout();
            this.tabControl1.SuspendLayout();
            this.tabPage6.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.tabPage7.SuspendLayout();
            this.tabPage4.SuspendLayout();
            this.tabPage8.SuspendLayout();
            this.SuspendLayout();
            // 
            // appList
            // 
            this.appList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.appList.Dock = System.Windows.Forms.DockStyle.Top;
            this.appList.FormattingEnabled = true;
            this.appList.Location = new System.Drawing.Point(0, 0);
            this.appList.Name = "appList";
            this.appList.Size = new System.Drawing.Size(526, 314);
            this.appList.Sorted = true;
            this.appList.TabIndex = 1;
            this.appList.SelectedIndexChanged += new System.EventHandler(this.appList_SelectedIndexChanged);
            // 
            // tabGlobal
            // 
            this.tabGlobal.Controls.Add(this.tabPage1);
            this.tabGlobal.Controls.Add(this.tabPage2);
            this.tabGlobal.Controls.Add(this.tabPage4);
            this.tabGlobal.Controls.Add(this.tabPage8);
            this.tabGlobal.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabGlobal.Location = new System.Drawing.Point(0, 0);
            this.tabGlobal.Name = "tabGlobal";
            this.tabGlobal.SelectedIndex = 0;
            this.tabGlobal.Size = new System.Drawing.Size(542, 430);
            this.tabGlobal.TabIndex = 3;
            this.tabGlobal.SelectedIndexChanged += new System.EventHandler(this.DoChangeForFilesTab);
            // 
            // tabPage1
            // 
            this.tabPage1.Controls.Add(this.tabApps);
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Size = new System.Drawing.Size(534, 404);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "Applications";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // tabApps
            // 
            this.tabApps.Controls.Add(this.tabPage3);
            this.tabApps.Controls.Add(this.tabPage5);
            this.tabApps.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabApps.Location = new System.Drawing.Point(0, 0);
            this.tabApps.Name = "tabApps";
            this.tabApps.SelectedIndex = 0;
            this.tabApps.Size = new System.Drawing.Size(534, 404);
            this.tabApps.TabIndex = 0;
            this.tabApps.SelectedIndexChanged += new System.EventHandler(this.DoPageChange);
            // 
            // tabPage3
            // 
            this.tabPage3.BackColor = System.Drawing.Color.Silver;
            this.tabPage3.Controls.Add(this.groupBox1);
            this.tabPage3.Controls.Add(this.appList);
            this.tabPage3.Location = new System.Drawing.Point(4, 22);
            this.tabPage3.Name = "tabPage3";
            this.tabPage3.Size = new System.Drawing.Size(526, 378);
            this.tabPage3.TabIndex = 0;
            this.tabPage3.Text = "List";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.button3);
            this.groupBox1.Controls.Add(this.btnSecurity);
            this.groupBox1.Controls.Add(this.button2);
            this.groupBox1.Controls.Add(this.button1);
            this.groupBox1.Location = new System.Drawing.Point(12, 325);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(495, 68);
            this.groupBox1.TabIndex = 8;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Global Options";
            // 
            // button3
            // 
            this.button3.BackColor = System.Drawing.Color.LightGray;
            this.button3.BackgroundImage = global::Thinxoft.XedusLive.Properties.Resources.help;
            this.button3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.button3.Font = new System.Drawing.Font("Verdana", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button3.Location = new System.Drawing.Point(11, 20);
            this.button3.Margin = new System.Windows.Forms.Padding(3, 3, 1, 3);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(189, 38);
            this.button3.TabIndex = 6;
            this.button3.Text = "HELP, i\'m getting crazy errors";
            this.button3.UseVisualStyleBackColor = false;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // btnSecurity
            // 
            this.btnSecurity.BackColor = System.Drawing.Color.LightGray;
            this.btnSecurity.BackgroundImage = global::Thinxoft.XedusLive.Properties.Resources.disable;
            this.btnSecurity.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.btnSecurity.Font = new System.Drawing.Font("Verdana", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btnSecurity.Location = new System.Drawing.Point(335, 20);
            this.btnSecurity.Margin = new System.Windows.Forms.Padding(1, 3, 3, 3);
            this.btnSecurity.Name = "btnSecurity";
            this.btnSecurity.Size = new System.Drawing.Size(152, 38);
            this.btnSecurity.TabIndex = 7;
            this.btnSecurity.Text = "Allow XSS chars";
            this.btnSecurity.UseVisualStyleBackColor = false;
            this.btnSecurity.Click += new System.EventHandler(this.btnSecurity_Click);
            // 
            // button2
            // 
            this.button2.BackColor = System.Drawing.Color.White;
            this.button2.BackgroundImage = global::Thinxoft.XedusLive.Properties.Resources.web;
            this.button2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.button2.Location = new System.Drawing.Point(204, 20);
            this.button2.Margin = new System.Windows.Forms.Padding(2, 3, 1, 3);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(34, 38);
            this.button2.TabIndex = 5;
            this.toolTip1.SetToolTip(this.button2, "Open the sample web site\r\nimplementation.");
            this.button2.UseVisualStyleBackColor = false;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button1
            // 
            this.button1.BackColor = System.Drawing.Color.LightGray;
            this.button1.BackgroundImage = global::Thinxoft.XedusLive.Properties.Resources.help;
            this.button1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            this.button1.Font = new System.Drawing.Font("Verdana", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.button1.Location = new System.Drawing.Point(241, 20);
            this.button1.Margin = new System.Windows.Forms.Padding(1, 3, 1, 3);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(91, 38);
            this.button1.TabIndex = 4;
            this.button1.Text = "x-file help";
            this.button1.UseVisualStyleBackColor = false;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // tabPage5
            // 
            this.tabPage5.Controls.Add(this.btnGetLocation);
            this.tabPage5.Controls.Add(this.label5);
            this.tabPage5.Controls.Add(this.txtLocation2);
            this.tabPage5.Controls.Add(this.label6);
            this.tabPage5.Controls.Add(this.label8);
            this.tabPage5.Controls.Add(this.txtDefaultDocs2);
            this.tabPage5.Controls.Add(this.txtApp2);
            this.tabPage5.Controls.Add(this.btnSave);
            this.tabPage5.Location = new System.Drawing.Point(4, 22);
            this.tabPage5.Name = "tabPage5";
            this.tabPage5.Size = new System.Drawing.Size(526, 378);
            this.tabPage5.TabIndex = 2;
            this.tabPage5.Text = "Edit";
            // 
            // btnGetLocation
            // 
            this.btnGetLocation.BackgroundImage = global::Thinxoft.XedusLive.Properties.Resources.open;
            this.btnGetLocation.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.btnGetLocation.Location = new System.Drawing.Point(472, 90);
            this.btnGetLocation.Name = "btnGetLocation";
            this.btnGetLocation.Size = new System.Drawing.Size(27, 19);
            this.btnGetLocation.TabIndex = 21;
            this.btnGetLocation.Click += new System.EventHandler(this.btnGetLocation_Click);
            // 
            // label5
            // 
            this.label5.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label5.Location = new System.Drawing.Point(13, 73);
            this.label5.Margin = new System.Windows.Forms.Padding(3, 3, 3, 1);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(71, 14);
            this.label5.TabIndex = 19;
            this.label5.Text = "Location:";
            // 
            // txtLocation2
            // 
            this.txtLocation2.BackColor = System.Drawing.Color.White;
            this.txtLocation2.Location = new System.Drawing.Point(12, 90);
            this.txtLocation2.Margin = new System.Windows.Forms.Padding(3, 1, 3, 1);
            this.txtLocation2.Name = "txtLocation2";
            this.txtLocation2.ReadOnly = true;
            this.txtLocation2.Size = new System.Drawing.Size(455, 21);
            this.txtLocation2.TabIndex = 18;
            // 
            // label6
            // 
            this.label6.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label6.Location = new System.Drawing.Point(13, 40);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(92, 19);
            this.label6.TabIndex = 17;
            this.label6.Text = "Default Docs";
            // 
            // label8
            // 
            this.label8.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label8.Location = new System.Drawing.Point(14, 13);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(85, 23);
            this.label8.TabIndex = 15;
            this.label8.Text = "Application";
            // 
            // txtDefaultDocs2
            // 
            this.txtDefaultDocs2.Location = new System.Drawing.Point(112, 39);
            this.txtDefaultDocs2.Name = "txtDefaultDocs2";
            this.txtDefaultDocs2.Size = new System.Drawing.Size(357, 21);
            this.txtDefaultDocs2.TabIndex = 14;
            // 
            // txtApp2
            // 
            this.txtApp2.Location = new System.Drawing.Point(113, 10);
            this.txtApp2.Name = "txtApp2";
            this.txtApp2.Size = new System.Drawing.Size(131, 21);
            this.txtApp2.TabIndex = 12;
            // 
            // btnSave
            // 
            this.btnSave.Location = new System.Drawing.Point(454, 370);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(63, 29);
            this.btnSave.TabIndex = 11;
            this.btnSave.Text = "Save";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // tabPage2
            // 
            this.tabPage2.Controls.Add(this.tabControl1);
            this.tabPage2.Location = new System.Drawing.Point(4, 22);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Size = new System.Drawing.Size(534, 404);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "Files";
            this.tabPage2.UseVisualStyleBackColor = true;
            // 
            // tabControl1
            // 
            this.tabControl1.Controls.Add(this.tabPage6);
            this.tabControl1.Controls.Add(this.tabPage7);
            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(0, 0);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(534, 404);
            this.tabControl1.TabIndex = 3;
            this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.DoChangeForFilesTab);
            // 
            // tabPage6
            // 
            this.tabPage6.BackColor = System.Drawing.Color.Silver;
            this.tabPage6.Controls.Add(this.listViewFiles);
            this.tabPage6.Controls.Add(this.menuStrip1);
            this.tabPage6.Location = new System.Drawing.Point(4, 22);
            this.tabPage6.Name = "tabPage6";
            this.tabPage6.Size = new System.Drawing.Size(526, 378);
            this.tabPage6.TabIndex = 0;
            this.tabPage6.Text = "All Files";
            this.tabPage6.Click += new System.EventHandler(this.tabPage6_Click);
            // 
            // listViewFiles
            // 
            this.listViewFiles.Dock = System.Windows.Forms.DockStyle.Fill;
            this.listViewFiles.GridLines = true;
            this.listViewFiles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
            this.listViewFiles.HideSelection = false;
            this.listViewFiles.LargeImageList = this.imageList1;
            this.listViewFiles.Location = new System.Drawing.Point(0, 24);
            this.listViewFiles.MultiSelect = false;
            this.listViewFiles.Name = "listViewFiles";
            this.listViewFiles.Size = new System.Drawing.Size(526, 354);
            this.listViewFiles.SmallImageList = this.imageList1;
            this.listViewFiles.Sorting = System.Windows.Forms.SortOrder.Ascending;
            this.listViewFiles.StateImageList = this.imageList1;
            this.listViewFiles.TabIndex = 2;
            this.listViewFiles.UseCompatibleStateImageBehavior = false;
            this.listViewFiles.View = System.Windows.Forms.View.List;
            this.listViewFiles.DoubleClick += new System.EventHandler(this.listViewFiles_DoubleClick);
            this.listViewFiles.SelectedIndexChanged += new System.EventHandler(this.listViewFiles_SelectedIndexChanged);
            // 
            // imageList1
            // 
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            this.imageList1.Images.SetKeyName(0, "folderup.jpg");
            this.imageList1.Images.SetKeyName(1, "folder.jpg");
            this.imageList1.Images.SetKeyName(2, "file.jpg");
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.actionsToolStripMenuItem,
            this.editToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(526, 24);
            this.menuStrip1.TabIndex = 7;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // actionsToolStripMenuItem
            // 
            this.actionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.openFolderToolStripMenuItem,
            this.deleteFolderToolStripMenuItem});
            this.actionsToolStripMenuItem.Name = "actionsToolStripMenuItem";
            this.actionsToolStripMenuItem.Size = new System.Drawing.Size(54, 20);
            this.actionsToolStripMenuItem.Text = "Actions";
            // 
            // openFolderToolStripMenuItem
            // 
            this.openFolderToolStripMenuItem.Name = "openFolderToolStripMenuItem";
            this.openFolderToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
            this.openFolderToolStripMenuItem.Text = "Browse Item";
            this.openFolderToolStripMenuItem.Click += new System.EventHandler(this.openFolderToolStripMenuItem_Click);
            // 
            // deleteFolderToolStripMenuItem
            // 
            this.deleteFolderToolStripMenuItem.Name = "deleteFolderToolStripMenuItem";
            this.deleteFolderToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
            this.deleteFolderToolStripMenuItem.Text = "Delete";
            this.deleteFolderToolStripMenuItem.Click += new System.EventHandler(this.deleteFolderToolStripMenuItem_Click);
            // 
            // editToolStripMenuItem
            // 
            this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.useNotepadToolStripMenuItem});
            this.editToolStripMenuItem.Name = "editToolStripMenuItem";
            this.editToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.editToolStripMenuItem.Text = "Edit";
            // 
            // useNotepadToolStripMenuItem
            // 
            this.useNotepadToolStripMenuItem.Name = "useNotepadToolStripMenuItem";
            this.useNotepadToolStripMenuItem.Size = new System.Drawing.Size(191, 22);
            this.useNotepadToolStripMenuItem.Text = "Edit File With Notepad";
            this.useNotepadToolStripMenuItem.Click += new System.EventHandler(this.useNotepadToolStripMenuItem_Click);
            // 
            // tabPage7
            // 
            this.tabPage7.Controls.Add(this.btnRemove);
            this.tabPage7.Controls.Add(this.btnOpen);
            this.tabPage7.Controls.Add(this.listView);
            this.tabPage7.Controls.Add(this.btnUplaod);
            this.tabPage7.Location = new System.Drawing.Point(4, 22);
            this.tabPage7.Name = "tabPage7";
            this.tabPage7.Size = new System.Drawing.Size(526, 378);
            this.tabPage7.TabIndex = 1;
            this.tabPage7.Text = "Upload";
            // 
            // btnRemove
            // 
            this.btnRemove.Location = new System.Drawing.Point(339, 365);
            this.btnRemove.Name = "btnRemove";
            this.btnRemove.Size = new System.Drawing.Size(58, 25);
            this.btnRemove.TabIndex = 3;
            this.btnRemove.Text = "Remove";
            this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
            // 
            // btnOpen
            // 
            this.btnOpen.Location = new System.Drawing.Point(430, 14);
            this.btnOpen.Name = "btnOpen";
            this.btnOpen.Size = new System.Drawing.Size(58, 25);
            this.btnOpen.TabIndex = 0;
            this.btnOpen.Text = "Open";
            this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
            // 
            // listView
            // 
            this.listView.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.listView.Location = new System.Drawing.Point(14, 43);
            this.listView.Name = "listView";
            this.listView.Size = new System.Drawing.Size(493, 314);
            this.listView.TabIndex = 1;
            this.listView.UseCompatibleStateImageBehavior = false;
            this.listView.View = System.Windows.Forms.View.List;
            // 
            // btnUplaod
            // 
            this.btnUplaod.Location = new System.Drawing.Point(404, 364);
            this.btnUplaod.Name = "btnUplaod";
            this.btnUplaod.Size = new System.Drawing.Size(104, 25);
            this.btnUplaod.TabIndex = 2;
            this.btnUplaod.Text = "Upload";
            this.btnUplaod.Click += new System.EventHandler(this.btnUplaod_Click);
            // 
            // tabPage4
            // 
            this.tabPage4.Controls.Add(this.connectToNowTab);
            this.tabPage4.Location = new System.Drawing.Point(4, 22);
            this.tabPage4.Name = "tabPage4";
            this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage4.Size = new System.Drawing.Size(534, 404);
            this.tabPage4.TabIndex = 2;
            this.tabPage4.Text = "Peer to Peer";
            this.tabPage4.UseVisualStyleBackColor = true;
            // 
            // connectToNowTab
            // 
            this.connectToNowTab.Location = new System.Drawing.Point(8, 6);
            this.connectToNowTab.Name = "connectToNowTab";
            this.connectToNowTab.Size = new System.Drawing.Size(518, 392);
            this.connectToNowTab.TabIndex = 0;
            // 
            // tabPage8
            // 
            this.tabPage8.Controls.Add(this.registerTab);
            this.tabPage8.Location = new System.Drawing.Point(4, 22);
            this.tabPage8.Name = "tabPage8";
            this.tabPage8.Size = new System.Drawing.Size(534, 404);
            this.tabPage8.TabIndex = 3;
            this.tabPage8.Text = "Xedus Registration";
            this.tabPage8.UseVisualStyleBackColor = true;
            // 
            // registerTab
            // 
            this.registerTab.Location = new System.Drawing.Point(8, 15);
            this.registerTab.Name = "registerTab";
            this.registerTab.Size = new System.Drawing.Size(518, 381);
            this.registerTab.TabIndex = 0;
            // 
            // openFile
            // 
            this.openFile.Multiselect = true;
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuItem10});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem2,
            this.menuItem6,
            this.menuItem7,
            this.menuItem9});
            this.menuItem1.Text = "Options";
            // 
            // menuItem2
            // 
            this.menuItem2.Enabled = false;
            this.menuItem2.Index = 0;
            this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem3,
            this.menuItem4,
            this.menuItem5});
            this.menuItem2.Text = "Peer  to Peer Server";
            // 
            // menuItem3
            // 
            this.menuItem3.Index = 0;
            this.menuItem3.Text = "Register";
            this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
            // 
            // menuItem4
            // 
            this.menuItem4.Index = 1;
            this.menuItem4.Text = "Connect";
            this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
            // 
            // menuItem5
            // 
            this.menuItem5.Index = 2;
            this.menuItem5.Text = "Disconnect";
            this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
            // 
            // menuItem6
            // 
            this.menuItem6.Index = 1;
            this.menuItem6.Text = "Sample Site";
            this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
            // 
            // menuItem7
            // 
            this.menuItem7.Index = 2;
            this.menuItem7.Text = "X-File Help";
            this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
            // 
            // menuItem9
            // 
            this.menuItem9.Index = 3;
            this.menuItem9.Text = "Close";
            this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
            // 
            // menuItem10
            // 
            this.menuItem10.Index = 1;
            this.menuItem10.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem8,
            this.btnShutdown});
            this.menuItem10.Text = "Xedus";
            // 
            // menuItem8
            // 
            this.menuItem8.Index = 0;
            this.menuItem8.Text = "Kill Server";
            this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
            // 
            // btnShutdown
            // 
            this.btnShutdown.Index = 1;
            this.btnShutdown.Text = "Shutdown";
            this.btnShutdown.Click += new System.EventHandler(this.btnShutdown_Click);
            // 
            // WebAdmin
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.BackColor = System.Drawing.Color.Silver;
            this.ClientSize = new System.Drawing.Size(542, 430);
            this.Controls.Add(this.tabGlobal);
            this.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MainMenuStrip = this.menuStrip1;
            this.MaximizeBox = false;
            this.Menu = this.mainMenu1;
            this.Name = "WebAdmin";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Xedus Administration Tool";
            this.Closing += new System.ComponentModel.CancelEventHandler(this.DoClose);
            this.Load += new System.EventHandler(this.WebAdmin_Load);
            this.tabGlobal.ResumeLayout(false);
            this.tabPage1.ResumeLayout(false);
            this.tabApps.ResumeLayout(false);
            this.tabPage3.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            this.tabPage5.ResumeLayout(false);
            this.tabPage5.PerformLayout();
            this.tabPage2.ResumeLayout(false);
            this.tabControl1.ResumeLayout(false);
            this.tabPage6.ResumeLayout(false);
            this.tabPage6.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.tabPage7.ResumeLayout(false);
            this.tabPage4.ResumeLayout(false);
            this.tabPage8.ResumeLayout(false);
            this.ResumeLayout(false);

        }
		#endregion		

		private void WebAdmin_Load(object sender, System.EventArgs e)
		{
		
		}

		private void DoPageChange(object sender, System.EventArgs e)
		{
			if(this.tabApps.SelectedTab.Text == "Edit")
			{				
				HttpApplication  xapp = settings.HttpApplications [app];
				this.txtApp2.Text = xapp.Name;
				
				this.txtLocation2.Text = xapp.DocumentRoot;
                StringBuilder sb = new StringBuilder();
                bool first = true;
                foreach (string defaultdoc in xapp.DefaultDocuments)
                {
                    if (first)
                        sb.Append(defaultdoc);
                    else
                        sb.Append("," + defaultdoc);

                }
				this.txtDefaultDocs2.Text = sb.ToString();				
			}

			
			if(this.tabApps.SelectedTab.Text == "List")
			{
				appList.Items.Clear();
				foreach(HttpApplication  app in settings.HttpApplications )
				{
					appList.Items.Add(app.Name);
				}
			}
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
            bool restart = false;
			HttpApplication  xapp = settings.HttpApplications [app];			
			xapp.Name = this.txtApp2.Text;
            
            if (xapp.DocumentRoot != this.txtLocation2.Text)
            {
                if (MessageBox.Show(this,"You have changed the document root for an active web.  In order for\nchanges to take plave Xedus must be restarted. Continue?","Restart required",MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    xapp.DocumentRoot = this.txtLocation2.Text;
                    restart = true;
                }
            }

            xapp.DefaultDocuments.Clear();
			string[] defaultDocs = this.txtDefaultDocs2.Text.Split(",".ToCharArray());
            foreach (string defaultdoc in defaultDocs)
            {
                xapp.DefaultDocuments.Add(defaultdoc);
            }
			Start.XedusState.XedusSettings.SaveSettings();

            if (restart)
            {

            }
		}

		private void btnOpen_Click(object sender, System.EventArgs e)
		{
			if(openFile.ShowDialog() == DialogResult.OK)
			{
				files  = openFile.FileNames;
				foreach(string file in files)
				{
					listView.Items.Add(new ListViewItem(file));
				}
			}
		}

		private void btnUplaod_Click(object sender, System.EventArgs e)
		{
			HttpApplication  xapp = settings.HttpApplications [app];		

			foreach(string file in files)
			{
				System.IO.File.Copy(file,xapp.DocumentRoot  + "/" + System.IO.Path.GetFileName(file),true);		
			}

			listView.Items.Clear();
		}

		private void DoChangeForFilesTab(object sender, System.EventArgs e)
		{
			if(this.tabGlobal.SelectedTab.Text == "Files")
			{
				HttpApplication  xapp = settings.HttpApplications [app];
                currentpath = xapp.DocumentRoot;

                LoadDirectoryFiles(xapp);
				
			}
		}

        private void btnRemove_Click(object sender, System.EventArgs e)
		{
			foreach(ListViewItem item in listView.SelectedItems)
			{
				listView.Items.Remove(item);
			}
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			

			foreach(ListViewItem item in listViewFiles.SelectedItems)
			{
                string path = dirfiles[item.Text];
                if (File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                else
                {
                    try
                    {
                        if (path == settings.HttpApplications[app].DocumentRoot)
                        {
                            MessageBox.Show("Deleting the default application root is not allowed","No",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                        }else
                            Directory.Delete(path);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Cannot delete empty directories");
                    }
                }
            }

			LoadDirectoryFiles(currentpath);

		}

		private void btnEditFile_Click(object sender, System.EventArgs e)
		{
            if (listViewFiles.SelectedItems.Count == 1)
            {
                EditFile(listViewFiles.SelectedItems[0].Text);
            }
        }

        private void EditFile(string name)
        {
            try
            {
                string path = dirfiles[name];
                if (File.Exists(path))
                    System.Diagnostics.Process.Start("notepad", path);
                else
                    MessageBox.Show(path + " is not a file.");
            }
            catch (Exception ex)
            {

            }
        }

		private void appList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.app = (string)appList.SelectedItem;
			this.Text = "Xedus Server  [" + this.app + "]";
		}

		private void btnDeleteApp_Click(object sender, System.EventArgs e)
		{
			
			//remove from list
			string dApp = (string)appList.SelectedItem;
			
			if(dApp != "default")
			{
				
				//remove from list
				appList.Items.Remove(appList.SelectedItem);

                MessageBox.Show("You  will have to delete the document root folder:" + settings.HttpApplications[dApp].DocumentRoot);

                //delete from settings
				settings.HttpApplications.DeleteApp(dApp);

				
				
			}
			
		}

		private void DoClose(object sender, System.ComponentModel.CancelEventArgs e)
		{
			e.Cancel = true;
			this.Hide();
		}

		private void btnConnect_Click(object sender, System.EventArgs e)
		{
		
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			
			System.Diagnostics.Process.Start("iexplore","http://localhost:4274/html/x-intro.htm");
		}

		private void menuItem3_Click(object sender, System.EventArgs e)
		{
			Start.MainForm.btnRegister_Click(sender,e);
		}

		private void menuItem4_Click(object sender, System.EventArgs e)
		{
			Start.MainForm.btnConnect_Click(sender,e);
		}

		private void menuItem5_Click(object sender, System.EventArgs e)
		{
			Start.MainForm.menuItem1_Click(sender,e);
		}

		private void menuItem6_Click(object sender, System.EventArgs e)
		{
			Start.MainForm.btnDefault_Click(sender,e);
		}

		private void menuItem7_Click(object sender, System.EventArgs e)
		{
			Start.MainForm.menuItem5_Click(sender,e);
		}

		private void menuItem8_Click(object sender, System.EventArgs e)
		{
			Start.MainForm.btnKill_Click(sender,e);
		}

		private void menuItem9_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show("Please email the development team directly at this email: developers@xedus.com");
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			Start.MainForm.btnDefault_Click(sender,e);
		}

        private void btnBrowse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FolderBrowserDialog fb = new FolderBrowserDialog();
            fb.ShowNewFolderButton = true;
            if (fb.ShowDialog() == DialogResult.OK)
            {
                this.txtLocation2.Text = fb.SelectedPath;
            }
            
            fb.Dispose();
        }

        private void btnBrowse2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
//            FolderBrowserDialog fb = new FolderBrowserDialog();
//            fb.ShowNewFolderButton = true;
//            if (fb.ShowDialog() == DialogResult.OK)
//            {
//                this.txtLocation.Text = fb.SelectedPath;
//            }
//
//            fb.Dispose();
        }

        private void btnSecurity_Click(object sender, EventArgs e)
        {
            if (Start.XedusState.XedusSettings.BlockXSS)
            {
                Start.XedusState.XedusSettings.BlockXSS = false;
               
            }
            else
            {
                Start.XedusState.XedusSettings.BlockXSS = true;
                
            }
            SetXssState();
        }
       
        private void btnOpenDir_Click(object sender, EventArgs e)
        {
            if (listViewFiles.SelectedItems.Count == 1)
            {
                OpenDirectory(listViewFiles.SelectedItems[0].Name);
            }

        }

        private void OpenDirectory(string name)
        {
            string dir = name;
            string target = dirfiles[dir];
            currentpath = target;
            LoadDirectoryFiles(target);
        }

        private void btnGetLocation_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fb = new FolderBrowserDialog();
            fb.ShowNewFolderButton = true;
            if (fb.ShowDialog() == DialogResult.OK)
            {
                this.txtLocation2.Text = fb.SelectedPath;
            }

            fb.Dispose();
        }

        private void listViewFiles_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                ListViewItem item = listViewFiles.SelectedItems[0];
                int type = item.ImageIndex;
                string name = item.Text ;
                switch (type)
                {
                    case 1: case 0:
                        OpenDirectory(name);                        
                        break;
                    case 2:
                        //EditFile(name);
                        break;
                    default:
                        break;
                }
                
            }
            catch (Exception ex)
            {
                
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.btnEditFile_Click(sender, e);
        }

        private void tabPage6_Click(object sender, EventArgs e)
        {

        }

        private void listViewFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                ListViewItem item = listViewFiles.SelectedItems[0];
                int type = item.ImageIndex;
                string name = item.Text;
                switch (type)
                {
                    case 1:
                        useNotepadToolStripMenuItem.Enabled = false;
                        break;
                    case 2:
                        useNotepadToolStripMenuItem.Enabled = true;
                        break;
                    default:
                        break;
                }

            }
            catch (Exception ex)
            {
                useNotepadToolStripMenuItem.Enabled = false;
            }
        }

        private void useNotepadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.btnEditFile_Click(sender, e);
        }

        private void deleteFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.btnDelete_Click(sender, e);
        }
        
        private void openFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem item = listViewFiles.SelectedItems[0];
                string target = dirfiles[item.Text];
                System.Diagnostics.Process.Start("explorer", target);
            }
            catch (Exception ex)
            {

            }
        }

        private void btnShutdown_Click(object sender, EventArgs e)
        {
            Start.ShutdownXedus();
        }
        
	}
}
